from datetime import datetime

from app import db


class BaseModel(db.Model):
    __abstract__ = True
    create_time = db.Column(db.DateTime, default=datetime.now)
    update_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
    remark = db.Column(db.Text, comment='备注')

class DutyTable(BaseModel):
    __tablename__ = 'duty_table'

    # STATUS = (
    #     (0, 'no'),
    #     (1, 'yes')
    # )

    id = db.Column(db.Integer, primary_key=True, autoincrement=True,comment='主键')
    date_ = db.Column(db.String(255), unique=True, nullable=False, comment='日期')
    # monthly = db.Column(db.Date, comment='月度数据')
    event = db.Column(db.String(255), comment='日程事件')
    wechat_id = db.Column(db.Integer, comment='微信id')

    def to_dict(self):
        import json
        zhibo = []
        try:
            event = json.loads(self.event)
            event.get('zhibo')
        except:
            pass

        return {
            'id': self.id,
            'date_': self.date_,
            'event': self.event,
            'wechat_id': self.wechat_id
            # 'is_active': self.STATUS[self.is_active][1]
        }

    def __str__(self):
        return self.date_